CREATE PROCEDURE [dbo].[PatientGet]
@Id			UNIQUEIDENTIFIER,	
@ReferrerId	UNIQUEIDENTIFIER,
@FirstName	NVARCHAR(50),
@LastName	NVARCHAR(50)
AS

SELECT	P.*
FROM	Patient P
WHERE	P.Id = ISNULL(@Id,Id)
AND		(@ReferrerId IS NULL OR P.ReferrerId = @ReferrerId)
AND		(@FirstName IS NULL OR P.FirstName = @FirstName)
AND		(@LastName IS NULL OR P.LastName = @LastName)
ORDER BY P.LastName, P.FirstName
	
RETURN @@ROWCOUNT